--[[--------------------------
--  Project Notes
--  Batch Craft Chat Filter
--   2013, Corwin MacGregor
------------------------------

Quartz3\Tradeskill\Tradeskill.lua:UNIT_SPELLCAST_START() etc

Blizzard_TradeSkillUI.lua:TradeSkillFrame_OnEvent() -> UPDATE_TRADESKILL_RECAST


GlobalStrings.lua	-> LOOT_ITEM_CREATED_SELF = "You create: %s."
			-> LOOT_ITEM_CREATED_SELF_MULTIPLE = "You create: %sx%d."

GetTradeSkillItemLink( index )
GetTradeSkillSelectionIndex() or TradeSkillFrame.selectedSkill

AchieveChannel.lua:OnEnable() -> ChatFrame_AddMessageFilter("CHAT_MSG_CHANNEL", filterFunc)
>> We want to use CHAT_MSG_LOOT and our filterFunc should `return true` to hide the line
>> what we need to do, then, is format the global strings to be used as regexp against the chatmsg
>>   and capture the %s for the link and the %d for the amount, and then capture the itemID out of
>>   the link to validate against the trade item we believe we are crafting...
>>   accumulate the amount, and at the end (which we know how?), we turn off the filter
>>   and print a formatted LOOT_ITEM_CREATED_SELF_MULTIPLE w/ itemLink and amount.

>> CHAT_MSG_TRADESKILL ??

----
[7/26/2013]

no no, like this:

(prehook) DoTradeSkill( .., repeat )
  recast = repeat
  expecting = 0
  AddChatFilter( batchFilter, CHAT_MSG_LOOT )

-> UNIT_SPELLCAST_SUCCEEDED:
  expecting = expecting + 1
  recast = recast - 1

-> TRADESKILL_CLOSE:  -- close tradeskill window during casting
-> TRADESKILL_SHOW:   -- open another tradeskill during casting
  recast = 1  -- these two events always finish the current cast

-> UNIT_SPELLCAST_FAILED_QUIET: -- user moved, or hit Esc
  recast = 1                    -- sometimes current cast Succeeds, sometimes not
  RegEvent( UNIT_SPELLCAST_INTERRUPTED )  -- listen for current cast having been interrupted

-> UNIT_SPELLCAST_INTERRUPTED:
  CleanUp()  -- schedule filter removal

-> (filter) CHAT_MSG_LOOT:
  if expecting >= 1 then
    expecting = expecting - 1
    parse the foo
  end
  if recast <= 0 then
    CleanUp() -- schedule filter removal
  end

----

-- if we were to put "CRAFT_LOOT" into the same Group as "LOOT", we wouldn't be able to custom the color
-- should we want to be able to do that?
-- on second thought, the actual "this is what you crafted" message at the end of the sequence /should/ be in "LOOT"
-- just as the actual "this is your skill-up aggregate" message should be in "SKILL"
-- it is the announcements and alerts and errors and debugs of BCCF we would want to have seperate coloring
tinsert("ChatTypeGroup["LOOT"], "CHAT_MSG_CRAFT_LOOT")

-- we should also determine a spoofable ChatTypeID for use with such code that uses it. perhaps a negative?

-- handle color of BCCF addon message(s) through BCCF addon config. prolly not good idea to do so through ChatFrameConfig
-- but... discuss with beahr.  perhaps there is logic to customizing color per registered chatframe


----
SKILL_RANK_UP = "Your skill in %s has increased to %d." -> %s1 = profession, %d1 = final skill level
associated filter: CHAT_MSG_SKILL
ERR_SKILL_UP_SI might be a GlobalString synonym/alternate for SKILL_RANK_UP.  uncertain which System actually uses.
	we'll go with SKILL_RANK_UP for now, but keep an eye out if any localization has different strings.


DoTradeSkill() -> Initialize: LootFilter, SkillFilter if needed
 ->> "LOOT": suppress, note lastEventArgs, update accumulator and counter
 ->> "SKILL": suppress if expected profession, note lastEventArgs, CleanUpSkill if local counter == 0 (???)
 ->> counter == 0: CleanUp
 -> CleanUp: remove loot filter, spoof loot msg
 -> CleanUpSkill: remove skill filter?, spoof skill msg


/dump GetTradeSkillInfo(GetMouseFocus():GetID())
/run idx=GetTradeSkillSelectionIndex(); repeat info={GetTradeSkillInfo(idx)}; idx=idx-1 until(info[2]=="subheader") if not info[7] then return end


local function GetTradeSkillSpecialtyName( index )
	local i = index
	repeat
		info = {GetTradeSkillInfo(i)}
		i = i - 1
	until (info[2] == "subheader" or info[2] == "header" or i < 1)

	if not info[7] then return end

	return info[1]
end


function multiselect( indices, ... )
	-- dont forget to put type-checking in here ~~ CmG
	local _rtns = {}
	for _,i in ipairs( indices ) do
		tinsert(_rtns, select(i,...))
	end
	return unpack(_rtns)
end

-------------------]]
-- // --